djyPrinter
djyPrinter
背景
在項(xiàng)目中用到小票打印功能,鑒于打印機(jī)支持pos命令由此而開發(fā)。 支持安卓4.0.4+ 測試設(shè)備htc(androi4.0.4),小米(androi4.4.4),華為暢享5s(androi5.1),華為mate8(androi6.0)
使用模塊過程遇到問題,可在論壇回復(fù)我
支持
-
打開藍(lán)牙搜索打印設(shè)備
-
通過連接指定
-
打印POS命令
模塊接口
scan
初始化藍(lán)牙并搜索附近的藍(lán)牙設(shè)備
scan({}, callback(ret,err))
callback(ret,err)
ret:
{ status: true //掃描開始 }
err:
-
類型:JSON對象
-
內(nèi)部字段:
{ msg: //錯誤信息 }
示例代碼
var BluetoothPrinter = api.require('djyPrinter');
BluetoothPrinter.scan({}, function (ret, err) { })
可用性
Android系統(tǒng)
可提供的1.0.0及更高版本
cancelScan
取消搜索附近的藍(lán)牙設(shè)備
cancelScan({}, callback(ret,err))
callback(ret,err)
ret:
{ status: true //掃描開始 }
err:
-
類型:JSON對象
-
內(nèi)部字段:
{ msg: //錯誤信息 }
示例代碼
var BluetoothPrinter = api.require('djyPrinter');
BluetoothPrinter.cancelScan({}, function (ret, err) { })
可用性
Android系統(tǒng)
可提供的1.0.0及更高版本
listBT
列出所有搜索到的藍(lán)牙設(shè)備
listBT({}, callback(ret,err))
callback(ret,err)
ret:
{
[
address: state: name: ]
}
err:
-
類型:JSON對象
-
內(nèi)部字段:
{ msg: //錯誤信息 }
示例代碼
var BluetoothPrinter = api.require('djyPrinter');
BluetoothPrinter.listBT({}, function (ret, err) { })
可用性
Android系統(tǒng)
可提供的1.0.0及更高版本
connect
連接(配對)藍(lán)牙設(shè)備。
connect({params}, callback(ret,err))
params
name
-
類型:字符串
-
描述:設(shè)備名稱 listBT 返回的設(shè)備名稱
callback(ret,err)
ret:
{ status: true //已經(jīng)連接 }
err
-
類型:JSON對象
-
內(nèi)部字段:
{ msg: //錯誤信息 }
示例代碼
var BluetoothPrinter = api.require('djyPrinter');
BluetoothPrinter.connect({
name: 'Gprinter_C20B' },function (ret, err) { });
可用性
Android系統(tǒng)
可提供的1.0.0及更高版本
disconnectBT
斷開設(shè)備
disconnectBT({}, callback(ret,err))
callback(ret,err)
ret:
{ status: true //已經(jīng)連接 }
err
-
類型:JSON對象
-
內(nèi)部字段:
{ msg: //錯誤信息 }
示例代碼
var BluetoothPrinter = api.require('djyPrinter');
BluetoothPrinter.disconnectBT(,function (ret, err) );
可用性
Android系統(tǒng)
可提供的1.0.0及更高版本
printPOSCommand
獲取當(dāng)前掃描到的所有外圍設(shè)備信息
printPOSCommand({params}, callback(ret,err))
params
{ msg: "" //pos命令以及需要打印的內(nèi)容連接的字符串 支持中文 }
callback(ret,err)
ret:
{ status: true //成功 }
err:
{ msg: //錯誤信息 }
示例代碼
var BluetoothPrinter = api.require('djyPrinter');
BluetoothPrinter.printPOSCommand({
msg: String.fromCharCode(29) + String.fromCharCode(33) + String.fromCharCode(17) + String.fromCharCode(27) + String.fromCharCode(97) + String.fromCharCode(1) + String.fromCharCode(10) + String.fromCharCode(10) + "零點(diǎn)美食城\n" + String.fromCharCode(29) + String.fromCharCode(33) + String.fromCharCode(0) + String.fromCharCode(27) + String.fromCharCode(97) + String.fromCharCode(0) + "西紅柿雞蛋面" + "12元" + "\n" + String.fromCharCode(27) + String.fromCharCode(97) + String.fromCharCode(0) + String.fromCharCode(10) + "總計(jì)12元" + "\n" }, function (ret, err) { });
可用性
Android系統(tǒng)
可提供的1.0.0及更高版本